package red.stu.pconstraint.engine;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import red.stu.pconstraint.pojo.ExecutionLocation;
import red.stu.pconstraint.pojo.ProcessStorage;

import java.util.List;

/**
 * 流程事件监听
 * @author yihrmc @stu.red
 * @date 2019/11/23 16:12
 */
public abstract class BaseProcessEventListener {

    /**
     * 当流程实例创建完毕
     * @param processStorage 创建的流程实例数据
     * @param workFlowEngine 所属引擎
     */
    public void onCreated(@NotNull ProcessStorage processStorage, @NotNull WorkFlowEngine workFlowEngine) {}

    /**
     * 当流程切换后
     * @param callStack
     * @param workFlowEngine
     */
    public void onChanged(@NotNull List<ExecutionLocation> callStack, @NotNull String processInstanceId, @NotNull WorkFlowEngine workFlowEngine) {}

    /**
     * 当流程被挂起后
     * @param processInstanceId
     * @param workFlowEngine
     */
    public void onSuspended(@Nullable String processInstanceId, @NotNull WorkFlowEngine workFlowEngine) {}

    /**
     * 当流程挂起恢复后
     * @param processInstanceId
     * @param workFlowEngine
     */
    public void onSuspendedRecovery(@Nullable String processInstanceId, @NotNull WorkFlowEngine workFlowEngine) {}

    /**
     * 当流程执行完成且成功后
     * @param processInstanceId
     * @param workFlowEngine
     */
    public void onSuccess(@Nullable String processInstanceId, @NotNull WorkFlowEngine workFlowEngine) {}

    /**
     * 当流程执行完成且失败后
     * @param processInstanceId
     * @param workFlowEngine
     */
    public void onFail(@Nullable String processInstanceId, @NotNull WorkFlowEngine workFlowEngine) {}

    /**
     * 当流程执行完成后(在成功和失败之后)
     * @param processInstanceId
     * @param workFlowEngine
     */
    public void onComplete(@Nullable String processInstanceId, @NotNull WorkFlowEngine workFlowEngine) {}

    /**
     * 当流程操作时出现异常
     * @param exception
     * @param processInstanceId
     * @param workFlowEngine
     */
    public void onThrowException(Exception exception, @Nullable String processInstanceId, @NotNull WorkFlowEngine workFlowEngine) {}

}
